package android.slc.adapter;

import java.io.Serializable;

public class LoadMoreDataFormatByFx<T extends Serializable> {
    protected final int baseOffset;
    protected int offset;
    protected int size;
    protected LoadModelCallbackFx<T> loadModelCallback;

    public int getBaseOffset() {
        return baseOffset;
    }

    public int getOffset() {
        return offset;
    }

    public void setOffset(int offset) {
        this.offset = offset;
    }

    public int getSize() {
        return size;
    }

    public void setSize(int size) {
        this.size = size;
    }

    public void setLoadModelCallback(LoadModelCallbackFx<T> loadModelCallback) {
        this.loadModelCallback = loadModelCallback;
    }

    public LoadModelCallbackFx<T> getLoadModelCallback() {
        return loadModelCallback;
    }

    public LoadMoreDataFormatByFx() {
        this(1, 10);
    }

    public LoadMoreDataFormatByFx(int offset, int size) {
        this.baseOffset = offset;
        this.offset = offset;
        this.size = size;
    }

    public void loadMoreComplete(PageModel<T> pageModel) {
        if (loadModelCallback != null) {
            loadModelCallback.loadMoreComplete(pageModel);
            loadModelCallback.setRefreshing(false);
        }
    }

    public void loadMoreFail(int pageIndex, int errorCode, String errorMsg) {
        if (loadModelCallback != null) {
            loadModelCallback.loadMoreFail(pageIndex, errorCode, errorMsg);
            loadModelCallback.setRefreshing(false);
        }
    }

    /**
     * 刷新，做清楚数据操作
     */
    public void refresh() {
        //offset = 1;
        if (loadModelCallback != null) {
            loadModelCallback.setRefreshing(true);
        }
    }


    public interface LoadModelCallbackFx<T extends Serializable> {
        default void loadMoreEnd() {
        }

        default void setRefreshing(boolean refresh) {
        }

        void loadMoreFail(int pageIndex, int errorCode, String errorMsg);

        void loadMoreComplete(PageModel<T> pageModel);
    }
}
